#include "DB/AsynDB_Login.h"
#include "Logic/Player.h"
#include "ProtoBuf/Client2Game/login.pb.h"
#include "ProtoBuf/ProtoBufMsg.h"
#include "WorldServer.h"

void AsynDB_Login::process()
{
	int reslut = 0;
	do 
	{
		if (m_result[0].num_rows() < 1)
		{
			reslut = Error_Password;
		}
		const mysqlpp::String& password = m_result[0][0]["password"]; 
		if (password.compare(m_passWord) == 0)
		{
			reslut = 0;
		}
		else
			reslut = Error_Password;

	} while (false);

	if (reslut == 0)
	{
		m_player->setState(LoginPlayer::State_Logined);

		const mysqlpp::String& name = m_result[0][0]["username"]; 

		m_player->setAccount(name.c_str());
	}
	else
		m_player->setState(LoginPlayer::State_None);

	loginResponse* pResponse = new loginResponse;
	pResponse->set_result(reslut);
	pResponse->set_hasplayer(m_result[1].num_rows() != 0);

	PacketProto* pPacket = new PacketProto(pResponse);
	m_player->sendPacket(pPacket);


}

AsynDB_Login::AsynDB_Login( LoginPlayer_PTR player,const std::string& password )
{
	m_player = player;
	m_passWord = password;
}

